﻿
$(function () {
    initOrder();
    init();

    $("#historylst").on("click", ".j_dhtz", function () {
        var ele = $(this);
        if (ele == null || ele.data("id") == "") {
            return false;
        }
        $.ajax({
            type: "get",
            data: {
                commodityId: ele.data("id")
            },
            url: "../Trade/ArrivalNotice",
            success: function (result) {
                if (result) {
                    util.Dialog.alert(result.msg);
                }
            }
        });
    });
});

var init = function () {
    util.Ajax.get_load("../Trade/CartHistory", {}, function (result) {
        if (result) {
            $("#historylst tbody").utastebars({
                tpl: $("#carthistorytpl"),
                context: result,
                emptytext: "<div class='order-none'>亲爱的用户，您目前尚无记录呦～<a href='http://www.yiguo.com/'>快去逛逛吧</a>～</div>"
            });
        }
    }, $("#historylst"));
    

    $("#orderlst").on("click", ".cancel", function () {
        var ele = $(this),
            oid = ele.data("oid");
        util.Dialog.confirm("是否要取消订单", function () { failurOrder(oid); });
    });

    
    
};

function failurOrder(oid) {
    $.ajax({
        type: "post",
        data: { "oid": oid },
        url: "../Trade/FailurOrder",
        success: function (result) {
            if (result.flag) {
                util.Dialog.alert("取消成功");
                initOrder();
            } else {
                util.Dialog.alert(result.msg);
            }
        }
    });
}

var initOrder = function () {

    util.Ajax.get_load("../Trade/OrdeResult", {}, function (result) {
        if (result) {
            $("#orderlst tbody").utastebars({
                tpl: $("#orderstpl"),
                context: result,
                emptytext: "<div class='order-none'>亲爱的用户，您目前尚无记录呦～<a href='http://www.yiguo.com/'>快去逛逛吧</a>～</div>"
            });
            //$(".countdown").each(function() {
            //    var ele = $(this);
            //    common.countDown(ele.attr("id"), ele.data("time"));
            //});
        }
    }, $("#orderlst"));
}